<template>
  <div class="aui-card-list">
    <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}"
      @searchReset="searchReset()">
      <el-col :span="6">
        <el-form-item label="字段类型">
          <el-input v-model="dataForm.columnType" placeholder="字段类型" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="数据库类型">
          <el-select v-model="dataForm.dbType" placeholder="请选择数据库类型" clearable>
            <el-option v-for="template in this.$getDictList('DATABASE_TYPE', false)" :key="template.val"
              :label="template.label" :value="template.val"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar :setting="{immediate:true}">
        <template v-slot:buttons>
          <el-button v-if="$hasPermission('dpd:dpdColumnType:save')" type="primary" @click="addOrUpdateHandle()">
            {{ $t('add') }}</el-button>
          <el-button v-if="$hasPermission('dpd:dpdColumnType:delete')" type="danger" @click="deleteHandle()">
            {{ $t('deleteBatch') }}</el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
        </template>
      </vxe-toolbar>
      <div class="aui-card-list-body-table">
      <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize
        @select-change="dataListSelectionChangeHandleVex" @select-all="dataListSelectionAllChangeHandleVex"
        :data="dataList" max-height="auto">
        <vxe-table-column type="checkbox" align="center" width="60"></vxe-table-column>
        <vxe-table-column field="columnTypeBiz" title="业务类型">
        </vxe-table-column>
        <vxe-table-column field="columnType" title="字段类型">
        </vxe-table-column>
        <vxe-table-column field="maxLength" title="默认长度" width="100" align="center">
        </vxe-table-column>
        <vxe-table-column field="numericScale" title="默认小数位数" width="100" align="center">
        </vxe-table-column>
        <vxe-table-column field="dbType" title="数据库类型" width="100" align="center">
          <template slot-scope="scope">
            {{$getDictLabel('DATABASE_TYPE', scope.row.dbType)}}
          </template>
        </vxe-table-column>
        <vxe-table-column field="remark" title="备注">
        </vxe-table-column>
        <vxe-table-column field="updateDate" title="更新时间" align="center" width="140">
        </vxe-table-column>
        <vxe-table-column title="handle" width="150" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('dpd:dpdColumnType:update')" type="text" size="small" icon="el-icon-edit"
              @click="addOrUpdateHandle(scope.row)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('dpd:dpdColumnType:delete')" type="text" size="small" icon="el-icon-delete"
              @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </vxe-table-column>
      </vxe-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './dpdColumnType-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      searchShow: true,
      mixinViewModuleOptions: {
        getDataListURL: '/dpd/dpdColumnType/page',
        getDataListIsPage: true,
        deleteURL: '/dpd/dpdColumnType',
        deleteIsBatch: true,
        exportURL: '/dpd/dpdColumnType/export'
      },
      dataForm: {
        columnType: '',
        dbType: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    }
  }
}
</script>
